Skip to content

Add automated cleanup workflow for stale lint/* branches#280

Merged
lachlangrose merged 6 commits intomasterfrom
copilot/create-cleanup-lint-workflow
Jan 15, 2026
Merged

Add automated cleanup workflow for stale lint/* branches#280
lachlangrose merged 6 commits intomasterfrom
copilot/create-cleanup-lint-workflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 15, 2026

The linter workflow creates lint/style-fixes-* branches that accumulate in the repository after their PRs are merged or closed.

Changes

New workflow: .github/workflows/cleanup-lint-branches.yml

  • Triggers: Daily at 00:00 UTC (cron), manual via workflow_dispatch with dry-run toggle (default: true)
  • Permissions: contents: write, pull-requests: read

Cleanup logic:

  • Lists branches matching lint/style-fixes-[0-9]+ via git for-each-ref
  • Queries PR status using GitHub CLI
  • Deletes branches where PR is merged/closed
  • Deletes orphaned branches (no PR) older than 7 days
  • Validates branch names with regex before deletion

Safety features:

  • Dry-run defaults to true for all trigger types
  • Branch name validation prevents injection: ^lint/style-fixes-[0-9]+$
  • Uses while IFS= read -r for safe iteration
  • Captures and logs deletion errors with exit codes
  • Pipeline failure detection via set -o pipefail

Output:

🧹 Starting lint branch cleanup...
Dry run mode: true
📋 Fetching lint branches...
Found 3 lint branches

🔍 Processing: lint/style-fixes-17199517932
  Found PR #123
  🔍 [DRY RUN] Would delete: PR #123 was merged

📊 Cleanup Summary
==================
Total lint branches processed: 3
Branches that would be deleted: 2
Branches skipped: 1
Original prompt

Problem Statement

The repository has accumulated many lint/* branches (e.g., lint/style-fixes-17199517932, lint/style-fixes-17199524890, etc.) that are created by the linter workflow in .github/workflows/linter.yml. These branches remain in the repository even after their associated pull requests are merged or closed, causing clutter.

Task

Create a new GitHub Actions workflow that periodically cleans up lint/* branches that have been merged or closed.

Requirements

  1. Create a new workflow file at .github/workflows/cleanup-lint-branches.yml

  2. Workflow should:

    • Run on a schedule (daily at 00:00 UTC using cron: 0 0 * * *)
    • Also be manually triggerable via workflow_dispatch
    • Have appropriate permissions (contents: write and pull-requests: read)
  3. The cleanup job should:

    • Use ubuntu-latest runner
    • Check out the repository with fetch-depth: 0 to get all branches
    • Use the GitHub API to:
      • List all branches matching the pattern lint/style-fixes-*
      • For each lint/* branch, check if there's an associated pull request
      • If the PR is merged or closed, delete the branch
      • If there's no associated PR (orphaned branch), optionally delete it after a certain age (e.g., 7 days old)
    • Use ${{ secrets.GITHUB_TOKEN }} for authentication
    • Print a summary of deleted branches
  4. Implementation details:

    • Use GitHub CLI (gh) or GitHub API via curl/actions to find and delete branches
    • Handle rate limiting appropriately
    • Include error handling for branches that cannot be deleted
    • Add appropriate logging to show which branches are being deleted and why
  5. Best practices:

    • Add comments explaining the workflow's purpose
    • Use descriptive step names
    • Include a dry-run mode option (via workflow_dispatch input) to preview what would be deleted without actually deleting

Example branch names to clean up

  • lint/style-fixes-17199517932
  • lint/style-fixes-17199524890
  • lint/style-fixes-17200129187
  • And many more similar branches

Success Criteria

  • The workflow successfully identifies lint/* branches
  • It correctly determines if PRs are merged/closed
  • It deletes only the appropriate branches
  • It provides clear logging of actions taken
  • It can be run manually or on schedule

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits January 15, 2026 06:43
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
…d loop handling

Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
Copilot AI changed the title [WIP] Add workflow for cleaning up lint branches Add automated cleanup workflow for stale lint/* branches Jan 15, 2026
Copilot AI requested a review from lachlangrose January 15, 2026 06:50
@lachlangrose lachlangrose marked this pull request as ready for review January 15, 2026 06:59
@lachlangrose lachlangrose merged commit c1459fb into master Jan 15, 2026
3 checks passed
@lachlangrose lachlangrose deleted the copilot/create-cleanup-lint-workflow branch January 15, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants